import Vue from 'vue'
import App from './App.vue'
import router from './router'

// 导入 axios
import axios from 'axios'

// 导入全局样式表
import '@/assets/css/global.less'

// 导入树形表格
import TreeTable from 'vue-table-with-tree-grid'

// 导入富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
// 导入富文本编辑器对应的样式
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

import NProgress from 'nprogress'

const baseURL = 'http://114.132.69.105:3000/'

axios.defaults.baseURL = baseURL

axios.interceptors.request.use(config => {
  NProgress.start()
  // 处理登录外的请求携带token
  if (config.url.includes('/admin') && !config.url.includes('/login')) {
    const tokenStr = window.sessionStorage.getItem('token')
    config.headers.Token = tokenStr
  }
  return config
})

axios.interceptors.response.use(config => {
  NProgress.done()
  return config
})

Vue.prototype.baseURL = baseURL

Vue.prototype.$http = axios

Vue.config.productionTip = false

// 注册树形表格
Vue.component('TreeTable', TreeTable)

// 将富文本编辑器，注册为全局可以的组件
Vue.use(VueQuillEditor)

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
